package com.config.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.config.common.Result;
import com.config.entity.Spread;
import com.config.service.SpreadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 流传线前端控制器
 * </p>
 *
 * @author Lu
 * @since 2021-02-04
 */

@Api (tags ="流传线设置页面接口")
@RestController
@RequestMapping ("/config/spread")
public class SpreadController {
	@Autowired
	SpreadService spreadService;

	//穿梭框右侧数据查询
	@ApiOperation ("获取右侧列表数据（Choose=1）")
	@GetMapping ("/findBySpChoose1")
	public Result selectByWrapper_spChoose1() {
		QueryWrapper<Spread> spreadQueryWrapper = new QueryWrapper<>();
		spreadQueryWrapper.like("sp_choose", 1);
		List<Spread> spreads = spreadService.list(spreadQueryWrapper);
		return Result.succ(spreads);
	}

	//穿梭框左侧数据查询
	@ApiOperation ("获取左侧列表数据（Choose=0）")
	@GetMapping ("/findBySpChoose0")
	public Result selectByWrapper_spChoose0() {
		QueryWrapper<Spread> spreadQueryWrapper = new QueryWrapper<>();
		spreadQueryWrapper.like("sp_choose", 0);
		List<Spread> spreads = spreadService.list(spreadQueryWrapper);
		return Result.succ(spreads);
	}

	@ApiOperation ("修改列表数据")
	@PutMapping ("/spupd")
	public Result upspChoose0(@RequestBody Spread spread) {
		boolean update = spreadService.updateById(spread);
		if (update) {
			return Result.succ(spread);
		} else {
			return Result.fail("修改失败");
		}
	}
}

